package org.example.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.example.entity.Area;
import org.example.entity.Boat;
import org.example.entity.Car;
import org.example.service.AreaService;
import org.example.service.ICarService;
import org.example.utils.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@Api(tags = "客车管理")
@RequestMapping("/scs")
@CrossOrigin
public class CarController {
    @Autowired
    private ICarService carService;

    @Autowired
    private AreaService areaService;

    //查询热门客车线路
    @ApiOperation("获取热门客车列表")
    @GetMapping("/get-hotCar")
    public Result queryHotBusLine(){
        //一对一查询  根据线路的出发地和目的地id查城市名称
        List<Car> list = carService.list(new QueryWrapper<Car>().eq("status",1));  //查询所有热门航线
        for (Car car : list) {
            Area area = areaService.getById(car.getBeginning());  //根据出发地id查城市名称
            car.setBeginningName(area.getName());
            Area area1 = areaService.getById(car.getDestination());  //根据目的地id查城市名称
            car.setDestinationName(area1.getName());
        }
        return new Result("200","查询成功",list);
    }
}
